<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class HhmVendorVerifiy extends Model
{
    protected $table = 'ims_hhm_vendor_verifiy';
    
    // 核销类型常量
    const TYPE_YOUHUI_ORDER = 1;  // 柚惠订单
    const TYPE_HHM_ORDER = 2;     // 换换猫订单
    
    protected $fillable = [
        'type',
        'outbound_id',
        'user_id',
        'vendor_id',
        'store_id',
        'created_at',
        'updated_at'
    ];
    
    /**
     * 禁用Laravel的自动时间戳管理
     */
    public $timestamps = false;
    
    /**
     * 关联核销用户
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
    
    /**
     * 关联门店
     */
    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id', 'id');
    }
    
    /**
     * 关联换换猫订单（当type=2时）
     */
    public function hhmOrder()
    {
        return $this->belongsTo(HhmOrder::class, 'outbound_id', 'id');
    }
    
    /**
     * 获取核销类型名称
     */
    public function getTypeNameAttribute()
    {
        $typeNames = [
            self::TYPE_YOUHUI_ORDER => '柚惠订单',
            self::TYPE_HHM_ORDER => '换换猫订单'
        ];
        
        return $typeNames[$this->type] ?? '未知类型';
    }
}
